package org.nobject.common.file;

import java.io.ByteArrayOutputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

/**
 * 序列化工具类
 *
 * @author bianrongjun
 * @version 1.0
 */
public class SerializeUtils {
	
	/** 
	 * 转化为字符
	 * @param obj 序列化对象
	 */
	public static byte[] toBytes(Serializable obj) {
        ObjectOutputStream oos = null;
        ByteArrayOutputStream baos = null;
        try {
            baos = new ByteArrayOutputStream();
            oos = new ObjectOutputStream(baos);
            oos.writeObject(obj);
            byte[] bytes = baos.toByteArray();
            return bytes;
        } catch (Exception e) {
        	throw new RuntimeException(e);
        }
    }
	
}
